package com.tianma315.admin.device.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.common.base.CoreServiceImpl;
import org.springframework.stereotype.Service;

import com.tianma315.admin.device.dao.DeviceTypeDao;
import com.tianma315.admin.device.domain.DeviceTypeDO;
import com.tianma315.admin.device.service.DeviceTypeService;

import java.util.List;

/**
 * 
 * <pre>
 * 设备类型
 * </pre>
 * <small> 2019-05-22 16:08:48 | Aron</small>
 */
@Service
public class DeviceTypeServiceImpl extends CoreServiceImpl<DeviceTypeDao, DeviceTypeDO> implements DeviceTypeService {

    @Override
    public Page<DeviceTypeDO> getDeviceTypeDOPage(Integer pageNumber, Integer pageSize, DeviceTypeDO deviceTypeDTO) {
        // 查询列表数据
        Page<DeviceTypeDO> page = new Page<>(pageNumber, pageSize);

        Wrapper<DeviceTypeDO> wrapper = new EntityWrapper<DeviceTypeDO>();
        wrapper.eq("state",0).like("type_name",deviceTypeDTO.getTypeName());
        wrapper.orderBy("create_date",false);
        page = selectPage(page, wrapper);
        int total = selectCount(wrapper);
        page.setTotal(total);
        return page;
    }

    @Override
    public boolean addDeviceTypeDO(DeviceTypeDO deviceTypeDO) {
        deviceTypeDO.setState(0);
        boolean flag = insert(deviceTypeDO);
        return flag;
    }

    @Override
    public boolean deleteDeviceTypeDO(Integer id) {
        DeviceTypeDO deviceTypeDO = new DeviceTypeDO();
        deviceTypeDO.setDeviceTypeId(id);
        deviceTypeDO.setState(1);
        boolean flag = updateById(deviceTypeDO);
        return flag;
    }

    @Override
    public List<DeviceTypeDO> getDeviceTypeDOList() {
        Wrapper<DeviceTypeDO> wrapper = new EntityWrapper<DeviceTypeDO>();
        wrapper.eq("state",0);
        List<DeviceTypeDO> deviceTypeDOList = selectList(wrapper);
        return deviceTypeDOList;
    }
    @Override
    public List<DeviceTypeDO> getDeviceTypeDOList(DeviceTypeDO deviceTypeDO) {
        Wrapper<DeviceTypeDO> wrapper = new EntityWrapper<DeviceTypeDO>();
        wrapper.eq("state",0);
        wrapper.like("type_name",deviceTypeDO.getTypeName());
        List<DeviceTypeDO> deviceTypeDOList = selectList(wrapper);
        return deviceTypeDOList;
    }

    @Override
    public List<DeviceTypeDO> getDeviceTypeByName(String DeviceTypeName) {
        Wrapper<DeviceTypeDO> wrapper = new EntityWrapper<DeviceTypeDO>();
        wrapper.eq("state",0);
        wrapper.eq("type_name",DeviceTypeName);
        List<DeviceTypeDO> deviceTypeDOList = selectList(wrapper);
        return deviceTypeDOList;
    }
}
